{extend name="extra@admin/content"}

{block name="content"}
<!--<span style="background: green;" onclick="change(1);">基本信息</span>-->
<!--<span style="background: green;" onclick="change(2);">图集</span>-->
<!--<span style="background: green;" onclick="change(3);">库存</span>-->
<form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='layui-form' style='padding-top:20px'>
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input name="name" value='{$vo.name|default=""}'
                   required="required" title="请输入商品名称" maxlength="50" placeholder="请输入商品名称" class="layui-input ">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品货号</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.good_number)}
            <input name="good_number" value='{$vo.good_number|default=""}'
                   required="required" title="请输入商品货号" maxlength="50" lay-verify="number" placeholder="请输入商品货号" class="layui-input ">
            {else}
            <input name="good_number" value='{$vo.good_number|default=""}' maxlength="50" lay-verify="number" required="required"
                   title="请输入商品名称称" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.unit)}
            <input name="unit" value='{$vo.unit|default=""}'
                   required="required" title="请输入商品单位" placeholder="请输入商品单位" class="layui-input ">
            {else}
            <input name="unit" value='{$vo.unit|default=""}' required="required"
                   title="请输入商品单位" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品分类</label>
        <div class="layui-input-block">
            <select name="cat_id" lay-verify="required" lay-filter="test" lay-search>
                <option value="">请选择商品分类</option>
                {volist name='category' id='v'}
                <option value="{$v.id}" {if condition="$vo.cat_id eq $v.id"} selected {/if}>{$v.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">扩展分类</label>
        <div class="layui-input-block">
            <select name="exp_cat" lay-verify="required" lay-filter="test" lay-search>
                <option value="">请选择扩展分类</option>
                {volist name='exp_category' id='v'}
                <option value="{$v.id}" {if condition="$vo.exp_cat eq $v.id"} selected {/if}>{$v.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">默认库存</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.price)}
            <input name="stock" value='{$vo.stock|default=""}'
                   required="required" title="请输入默认库存" placeholder="请输入默认库存" class="layui-input ">
            {else}
            <input name="stock" value='{$vo.stock|default=""}' required="required"
                   title="请输入默认库存" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品价格</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.price)}
            <input name="price" value='{$vo.price|default=""}'
                   required="required" title="请输入商品价格" placeholder="请输入商品价格" class="layui-input ">
            {else}
            <input name="price" value='{$vo.price|default=""}' required="required"
                   title="请输入商品价格" class="layui-input">
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员价格</label>
        <div class="layui-input-block">
            {if $vo and isset($vo.price)}
            <input name="member_price" value='{$vo.member_price|default=""}'
                   title="请输入会员价格" placeholder="请输入会员价格" class="layui-input ">
            注：仅是会员商品的是时候显示
            {else}
            <input name="member_price" value='{$vo.member_price|default=""}'
                   title="请输入商品价格" class="layui-input">
            <p style="color:red;">注：仅是会员商品的是时候显示</p>
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员类型</label>
        <div class="layui-input-block">
            {foreach name="level" item="v"}
                <input type="radio"  name="member_level_id" value="{$v.code}" title="{$v.title}" {if condition="$vo.member_level_id eq $v.id"} checked {/if}>
            {/foreach}
            <p style="color:red;">注：若是会员商品，请选择对应的会员类型；否则请选择普通会员商品</p>
        </div>
    </div>
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">是否线上</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="radio"  name="is_online" value="1"  title="允许" checked>-->
            <!--<input type="radio"  name="is_online" value="0"  title="不允许" >-->
        <!--</div>-->
    <!--</div>-->
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">是否上架</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input type="radio"  name="status" value="1"  title="上架" checked>-->
            <!--<input type="radio"  name="status" value="0"  title="下架" >-->
        <!--</div>-->
    <!--</div>-->
    <div class="layui-form-item">
        <label class="layui-form-label">商品简介</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入商品简介不超过100个字符" maxlength="200" title="请输入商品简介" required="required" class="layui-textarea" name="description">{$vo.description|default=""}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品图片</label>
            <div class="uploadimage" style="margin-left:1%;">
                <input type="hidden"  name="logo" value="{if condition='!empty($vo.logo)'} {$vo.logo} {/if}" />
            </div>
            <a data-file="one" data-field="logo" data-type="png,jpg,jpeg" data-uptype="qiniu" href="javascript:void(0)"
               class="uploadbutton"><i style="font-size:30px;" class="fa fa-upload" title="点击上传"></i></a>
            {if $vo and !empty($vo.logo)}
            <script>
                $(function(){
                    var img = "{$vo.logo}";
                    require(['jquery'], function () {
                        $('[name="logo"]').parent().attr('data-tips-image', this.value).css('backgroundImage', 'url(' + img + ')');
                    });
                });
            </script>
            {/if}
            <script>
                require(['jquery'], function () {
                    $('[name="logo"]').on('change', function () {
                        $(this).parent().attr('data-tips-image', this.value).css('backgroundImage', 'url(' + this.value + ')');
                    });
                });
            </script>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品详情</label>
        <div class="layui-input-block">
            <textarea name="detail" required="required">{$vo.detail}</textarea>
            <script type="text/javascript">
            require(['ckeditor'], function () {
                var editor = window.createEditor('[name="detail"]');
                // 设置内容
                // editor.setData('修改内容');
                // 获取内容
                var content = editor.getData();
                console.log(content);
            });
            </script>
            <script>
                layui.use('code', function () {
                    layui.code({encode: true});
                });
            </script>
        </div>
    </div>

    <div class="hr-line-dashed"></div>
    <div class="col-sm-4 col-sm-offset-2">
        {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
        {if isset($vo['id'])}<input type='hidden' value='{$vo.status}' name='status'/>{else /}<input type='hidden' value='0' name='status'/>{/if}
        {if isset($vo['id'])}<input type='hidden' value='{$vo.is_online}' name='is_online'/>{else /}<input type='hidden' value='0' name='is_online'/>{/if}
        <div class="layui-form-item text-center">
            <button class="layui-btn" type="submit">保存</button>
        </div>
    </div>
    <script type="text/javascript">
    layui.use('form', function(){
        var form = layui.form;      //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });

    function reduce(obj){
        $(obj).parent().remove();
    }

    form.on('select(test)', function(data){

    });

    form.verify({
        price: function(value, item){ //value：表单的值、item：表单的DOM对象
//            if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
//                return '用户名不能有特殊字符';
//            }
//            if(/(^\_)|(\__)|(\_+$)/.test(value)){
//                return '用户名首尾不能出现下划线\'_\'';
//            }
//            if(/^\d+\d+\d$/.test(value)){
//                return '用户名不能全为数字';
//            }
            if(test(value)<100){
                return '必须大于100';
            }
        }

    });

</script>
</form>

{/block}
